package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.ParkingRuleBiz;
import guda.stark.dal.dao.ParkingRuleDAO;
import guda.stark.dal.dataobject.ParkingRuleDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class ParkingRuleBizImpl implements ParkingRuleBiz{

    private final static Logger logger = LoggerFactory.getLogger(ParkingRuleBizImpl.class);

    @Autowired
    private ParkingRuleDAO parkingRuleDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            ParkingRuleDO parkingRuleDO = parkingRuleDAO.getParkingRuleById(id);
            bizResult.data.put("parkingRuleDO", parkingRuleDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query ParkingRule error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = parkingRuleDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<ParkingRuleDO> parkingRuleList = parkingRuleDAO.selectForPage(baseQuery);
            bizResult.data.put("parkingRuleList", parkingRuleList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view ParkingRule list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            parkingRuleDAO.delParkingRuleById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete parkingRule error", e);
        }
        return bizResult;
    }

    public BizResult create(ParkingRuleDO parkingRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = parkingRuleDAO.insert(parkingRuleDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create ParkingRule error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(ParkingRuleDO parkingRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            parkingRuleDAO.updateByIdSelective(parkingRuleDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update ParkingRule error", e);
        }
        return bizResult;
    }


}
